package readFile;


import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.springframework.util.StopWatch;

import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class ReadFile01 {

    public static void main(String[] args) throws IOException {
        StopWatch stopWatch  = new StopWatch();
        stopWatch.start();
        List<String> lines = FileUtils.readLines(new File("D:\\code.txt"), StandardCharsets.UTF_8);
        for(String line : lines){

        }
        stopWatch.stop();
        System.out.println("read all lines spend " + stopWatch.getTotalTimeSeconds()+ " s");
        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage();
        long initMemory = memoryUsage.getInit();
        long usedMemory = memoryUsage.getUsed();
        System.out.println("init memory :" + initMemory/ (1024 * 1024) + "M");
        System.out.println("used memory :" + usedMemory/ (1024 * 1024) + "M");
    }
}
